import { defineStore } from 'pinia';
import { APIData, ITch, ISTU, ITchStageParams, IStageList } from '../type';
import { RouteRecordRaw } from 'vue-router';

export const useUserStore = defineStore({
  id: 'userStore',
  //共享数据,自执行函数
  state: () => ({
    userInfo: {} as any,
    role: '',
    isAdmin: 0,
    currentStage: 0,
    currentDepartment: 0,
    stageList: [] as Array<IStageList>,
    roleRoutes: [] as Array<RouteRecordRaw>,
  }),
  //类似于methods 同步异步都可以
  actions: {
    clearStore: function () {
      this.userInfo = {} as any;
      this.role = '';
      this.isAdmin = 0;
      this.currentStage = 0;
      this.currentDepartment = 0;
      this.stageList = [] as Array<IStageList>;
      this.roleRoutes = [] as Array<RouteRecordRaw>;
    },
    // getTchAllStage: async function () {
    //   const params: ITchStageParams = { workId: this.userInfo.workId }; //有个坑,就是即使参数只有一个,也要用对象包装起来,否则axios报错 target must an object
    //   const res: APIData = await api.findAll(params, this.role, 'tchStage');
    //   return res;
    // },
  },
  //类似于computed,是有缓存的
  getters: {
    // newName(): string {
    //   return `${this.list.abc}~~getters`;
    // },
  },
});
